package com.gobang.demo.config;

import com.gobang.demo.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class AppInterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    // 拦截器会拦截 jQuery 那些静态文件，排序一下
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**")
                .excludePathPatterns("/gobang_login.html")   // 排除登录HTML
                .excludePathPatterns("/gobang_register.html")   // 排除注册HTML
                .excludePathPatterns("/user/login/**")     // 排除登录api接口
                .excludePathPatterns("/user/register/**")  // 排除注册api接口
                .excludePathPatterns("/css/**")        // 排除所有静态文件
                .excludePathPatterns("/pic/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/**.ico");
    }
}
